***********************************************************************
*This file builds vars on schooling and employment from the Census/ACS*
***********************************************************************

use "$list/czones_list.dta", clear
expand 2
gen year=1990
bys czone: replace year=2000 if _n==2

merge m:1 czone using "$clean_data_lmarket/czone1990_schooling_employment.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2000_schooling_employment.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2008_schooling_employment.dta", assert(3) nogenerate

foreach var of varlist ipums_* {
quiet replace `var' = 0 if mi(`var')
}

****************************
*		 Employment		   *
****************************

foreach emp in emp uemp npart emp_ft emp_pt emp_ps {

gen d_`emp' = 0.7*100*((ipums_`emp'_2000/ipums_pop_2000)-(ipums_`emp'_1990/ipums_pop_1990)) if year == 1990
replace d_`emp' = 100*((ipums_`emp'_2008/ipums_pop_2008)-(ipums_`emp'_2000/ipums_pop_2000)) if year == 2000

foreach educ in b a l {
gen d_`emp'_`educ' = 0.7*100*((ipums_`emp'_`educ'_2000/ipums_pop_`educ'_2000)-(ipums_`emp'_`educ'_1990/ipums_pop_`educ'_1990)) if year == 1990
replace d_`emp'_`educ' = 100*((ipums_`emp'_`educ'_2008/ipums_pop_`educ'_2008)-(ipums_`emp'_`educ'_2000/ipums_pop_`educ'_2000)) if year == 2000

}
}

*Ratio
foreach year in 1990 2000 2008 {
gen ipums_emp_ratio_ba_`year' = (ipums_emp_b_`year'/ipums_pop_b_`year')/(ipums_emp_a_`year'/ipums_pop_a_`year')
gen ipums_emp_ratio_bl_`year' = (ipums_emp_b_`year'/ipums_pop_b_`year')/(ipums_emp_l_`year'/ipums_pop_l_`year')
gen ipums_emp_ratio_al_`year' = (ipums_emp_a_`year'/ipums_pop_a_`year')/(ipums_emp_l_`year'/ipums_pop_l_`year')
}

foreach emp in emp_ratio {
foreach educ in ba bl al {
gen d_`emp'_`educ' = 0.7*100*((ipums_`emp'_`educ'_2000)-(ipums_`emp'_`educ'_1990)) if year == 1990
replace d_`emp'_`educ' = 100*((ipums_`emp'_`educ'_2008)-(ipums_`emp'_`educ'_2000)) if year == 2000
}
}

****************************
* Employment and schooling *
****************************

*Employment of students who work between 20 and 30 hours
foreach year in 1990 2000 2008 {

gen ipums_emp_pt20_30_sc_`year' = ipums_emp_pt_sc_`year' - ipums_emp_ps_sc_`year'

foreach age in a19_34 a35_64 {

gen ipums_emp_pt20_30_sc_`age'_`year' = ipums_emp_pt_sc_`age'_`year' - ipums_emp_ps_sc_`age'_`year'

}
}

foreach emp in emp uemp npart emp_ft emp_pt emp_pt20_30 emp_ps {
foreach school in sc {

gen d_`emp'_`school' = 0.7*100*((ipums_`emp'_`school'_2000/ipums_pop_2000)-(ipums_`emp'_`school'_1990/ipums_pop_1990)) if year == 1990
replace d_`emp'_`school' = 100*((ipums_`emp'_`school'_2008/ipums_pop_2008)-(ipums_`emp'_`school'_2000/ipums_pop_2000)) if year == 2000

foreach age in a19_34 a35_64 {
gen d_`emp'_`school'_`age' = 0.7*100*((ipums_`emp'_`school'_`age'_2000/ipums_pop_`age'_2000)-(ipums_`emp'_`school'_`age'_1990/ipums_pop_`age'_1990)) if year == 1990
replace d_`emp'_`school'_`age' = 100*((ipums_`emp'_`school'_`age'_2008/ipums_pop_`age'_2008)-(ipums_`emp'_`school'_`age'_2000/ipums_pop_`age'_2000)) if year == 2000
}
}
}


save "$final_data_outcomes/czone_StudentsEmployment.dta", replace






